'use strict'; 
// url 全球统一资源定位符，对于网站资源的一种简洁表达形式，也称为网址
// url一共提供三个方法，分别为: 
//     url.parse()
//     url.format()
//     url.resolve()

    let url = require('url');   

    // let address = 'https://www.baidu.com/s?ie=utf-8&f=8&rsv_bp=1&tn=baidu&wd=node.js%E6%B2%A1%E6%9C%89%E8%B0%83%E8%AF%95%E9%80%82%E9%85%8D%E5%99%A8%EF%BC%8C%E6%97%A0%E6%B3%95%E5%8F%91%E9%80%81%E2%80%9Cvariables%E2%80%9D&oq=%25E7%25AE%2580%25E4%25B9%25A6&rsv_pq=b63c63eb00082bb0&rsv_t=a4capgAV3snb1%2FwP9XbsVNorWCRAh07GDjnSq0fSWCCdKUsUEYwzOuYGSGY&rqlang=cn&rsv_enter=1&rsv_dl=tb&rsv_sug3=9&rsv_sug1=5&rsv_sug7=100&rsv_n=2&rsv_sug2=0&rsv_btype=t&inputT=4498&rsv_sug4=5470'

    // let q = url.parse(address, true);

    // console.log(q.host);

    // console.log(q.pathname);
    // console.log(q.search);

// 将一个URL对象转换成一个URL字符串
    console.log(url.format({
        protocol:'http:',
        host: 'www.example.com',
        pathname:'/p/a/t/h',
        serach: 'query=string'
    }));

    let a = '/one/two/three'
    let b = 'http://example.com/'
    let c = 'http://example.com/one'

// 拼接路径 - 找寻在 斜杆 与 反斜杠细节产生的结果
//  1. 替换最后一个路径信息： /own/two/three => /own/two/four
    console.log('拼接URL1：' + url.resolve(a,'four'));

//  2. /path => /eour1  => 替换
    console.log('拼接URL2：' + url.resolve('/path','eour1'));

//  3. ./path => eour2  => 替换
    console.log('拼接URL3：' + url.resolve('./path','eour2'));

//  4. /path => /eour3  => 替换
    console.log('拼接URL4：' + url.resolve('/path','/eour3'));

//  5. 'http://example.com/' => 'http://example.com/own' => 拼接
    console.log('拼接URL5: ' + url.resolve(b,'own'));

//  6. 'http://example.com/one' => 'http://example.com/swo' => 替换
    console.log('拼接URL3: ' + url.resolve(c, '/swo'));